<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">体验店管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">体验店基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                	<div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">用户id：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="accountId" class="form-control" 
                                                   readOnly>
                                        </div>
                                    </div>
                                	<div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">用户昵称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nickname" class="form-control" 
                                                   readOnly>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">体验店名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopName" class="form-control" placeholder="请输入体验店名称"
                                                   required>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">体验店地址：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopAddress" class="form-control"
                                                   placeholder="请输入体验店地址">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">联系电话：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopPhone" class="form-control"
                                                   placeholder="请输入体验店联系电话">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">微信号：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopWechatNumber" class="form-control"
                                                   placeholder="请输入体验店微信号">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group" id="sale_seller">
                                        <label class="col-lg-2 clo-md-2 control-label">销售范围(供应商)：</label>
                                        <div class="col-lg-8" id="sellerList">
                                        	<c:forEach var="item" items="${productSellerList}" varStatus="status">
						                             <input type="checkbox" name="saleSellerArea" value="${item.productSellerId}">${item.productSellerName}
						                    </c:forEach>
                                        </div>
                                    </div>
                                    
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="cashRed_modify()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                    取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	
	var images = [],descs=[];
	var currentI = 0;
	$(function(){
		var accountId = "${accountId}";
		var baseURL = "${webPath}/shopMessage/detail";
	  	var json_package = {
	       "head": {},
	       "body": {
	       	"accountId": accountId
	       }
	   	}
		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	      if (typeof result == 'string') result = JSON.parse(result);
	      if (result.body.result == '1') {
	          alert(result.body.description)
	      } else {
	      	var shopMessage = result.body.shopMessage;
	      	$("#accountId").val(shopMessage.accountId);
	      	$("#nickname").val(shopMessage.nickname);
	      	$("#shopName").val(shopMessage.shopName);
	      	$("#shopAddress").val(shopMessage.shopAddress);
	      	$("#shopPhone").val(shopMessage.shopPhone);
	      	$("#shopWechatNumber").val(shopMessage.shopWechatNumber);
          	
	      	var body = result.body;
          	$("#sellerList").empty();
          	console.log(body.productSellerList);
          	if(body.productSellerList != undefined && body.productSellerList.length>0){
	      		var productSellerListString = '';
	      		for(var i=0;i<body.productSellerList.length;i++){
	      			if(body.productSellerList[i].hava == 1){
	      				productSellerListString += '<input type="checkbox" name="saleSellerArea" value="'+body.productSellerList[i].id+'" checked>'+body.productSellerList[i].name+" ";
	      			}else{
	      				productSellerListString += '<input type="checkbox" name="saleSellerArea" value="'+body.productSellerList[i].id+'">'+body.productSellerList[i].name+" ";
	      			}
	      		}
	      		$("#sellerList").append(productSellerListString);
	      	}
	      }
	  	})
	});
	
	function cashRed_modify() {
		var type = "${type}";
		if(type == "3"){
			alert("当前账号无权限查看此功能");
			return;
		}
		
    	var baseURL = "${webPath}/shopMessage/modify";
    	var accountId = "${accountId}";
    	var shopName = $('#shopName').val();
        var shopAddress = $('#shopAddress').val();
        var shopPhone = $('#shopPhone').val();
        var shopWechatNumber = $('#shopWechatNumber').val();
        
        var saleSellerArea =[]; 
        $('input[name="saleSellerArea"]:checked').each(function(){ 
        	saleSellerArea.push($(this).val()); 
        }); 
        
        var json_package = {
       		"head": {},
            "body": {
            	"accountId":accountId,
                "shopName": shopName,
                "shopAddress": shopAddress,
                "shopPhone": shopPhone,
                "shopWechatNumber": shopWechatNumber,
                "saleSellerArea":saleSellerArea
            }
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert('修改成功！')
                window.location.reload(true);
            } else {
                alert('修改失败！')
            }
        })
    }
	$(function () {
        $('#cancel').click(function () {
            window.location.href = "${webPath}toShopMessage";
        })
    });
    $(document).ready(function (e) {
        $('#pro_info').keydown(function () {
            var len = $(this).val().length;
            if (len >= 100) {
                var num = $(this).val().substring(0, 99);
                $(this).val(num);
                alert("超过字数限制")
            }
        })
    });
    $(document).ready(function (e) {
        $('#pro_desc').keydown(function () {
            var len = $(this).val().length;
            if (len >= 140) {
                var num = $(this).val().substring(0, 139);
                $(this).val(num);
                alert("超过字数限制")
            }
        })
    });
</script>
</body>
</html>